package data_treating

import (
	"fmt"
	"github.com/google/uuid"
	"os"
	"time"
)

// 初始化文件目录
func init() {
	wd, _ := os.Getwd()
	//正常图片
	normalDir := fmt.Sprintf("%s%s", wd, "/"+normalPictureDir)
	isExist, _ := pathExists(normalDir)
	if !isExist {
		_ = os.Mkdir(normalDir, 0755)
	}
	//异常图片
	abnormalDir := fmt.Sprintf("%s%s", wd, "/"+abnormalPictureDir)
	isExist, _ = pathExists(abnormalDir)
	if !isExist {
		_ = os.Mkdir(abnormalDir, 0755)
	}
	return
}

// 获取文件
func GetFilePath() (res string) {
	wd, _ := os.Getwd()
	filePath := time.Now().Format(TimeFormat)
	dir := fmt.Sprintf("%s%s%s", wd, "/"+normalPictureDir+"/", filePath)
	isExist, _ := pathExists(dir)
	res = fmt.Sprintf("%s%s%s%s%s", wd, "/"+normalPictureDir+"/", filePath, "/", fmt.Sprintf("%s%s%s%s", time.Now().Format("2006-01-02-15-04"), ".", uuid.New().String(), ".jpg"))
	if !isExist {
		_ = os.Mkdir(dir, 0755)
	}
	return
}
